package main

func main()  {

}

type phTreeNode struct {
	val int
	left *phTreeNode
	right *phTreeNode
}
func treeDeeps(node *phTreeNode) int{
	if node == nil {
		return 0
	}
	left := treeDeeps(node.left)
	right := treeDeeps(node.right)
	if left > right {
		return left + 1
	}else {
		return right + 1
	}
}

func isphTree(root *phTreeNode) bool {
	if root == nil {
		return true
	}
	c := treeDeeps(root.left) - treeDeeps(root.right)
	if c >= 1 || c <=-1 {
		return false
	}
	return isphTree(root.left) && isphTree(root.right)
}